<?php
/**
 * Title
 * Created by Jason.
 * User: Administrator
 * Date: 2019/12/9 0009
 * Time: 下午 2:48
 */

namespace app\index\service;


use app\index\abstracts\Person;
use app\index\abstracts\State;

class Visitor
{
    private $elements = array();

    public function add(Person $element){
        array_push($this->elements,$element);
    }

    public function remove(Person $element){
        foreach ($this->elements as $key=>$val){
            if($key == $element ){
                unset($this->elements[$key]);
            }
        }
    }

    public function display(State $visitor){
        foreach ($this->elements as $val){
            $val->accept($visitor);
        }
    }
}